package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author kaoM1Jy
 * @date 2025/10/9 17:27
 * @description:
 */
@Slf4j
@RestController
@RequestMapping("/activities")
@SuppressWarnings("all")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

  @GetMapping("/type/{type}")
  public Result getByType(@PathVariable Integer type) {
    List<Activity> list= activityService.getByType(type);
    return Result.success(list);
  }

    @PutMapping
    public Result update(@RequestBody Activity activity) {
        activityService.update(activity);
        return Result.success();
    }


    @GetMapping("/{id}")
    public Result getByID(@PathVariable Integer id) {
        Activity activity = activityService.getByID(id);
        return Result.success(activity);
    }


@DeleteMapping("/{id}")
public Result deleteByID(@PathVariable Integer id) {
    activityService.deleteByID(id);
    return Result.success();
}

    @PostMapping
    public Result add(@RequestBody Activity activity) {
        activityService.add(activity);
        return Result.success();
    }


    @RequestMapping
    public Result page(@RequestParam(required = false) Integer channel,
                       @RequestParam(required = false) Integer type,
                       @RequestParam(required = false) Integer status,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        PageResult<Activity> result = activityService.page(channel, type, status, page, pageSize);
        return Result.success(result);
    }

}
